﻿Imports System.Xml
Imports System.Xml.Xsl

Partial Class UserCuntrols_RandomHyperlinkl
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        PopulateLinks()
    End Sub

    Private Sub PopulateLinks()
        Dim oXmlDocument As New XmlDocument()
        oXmlDocument.Load(Server.MapPath(_XMlFile))
        Dim oXslDocument As New XslCompiledTransform()
        oXslDocument.Load(Server.MapPath("~/XSL/Hyperlinks.xslt"))
        Dim _Stream As New System.IO.MemoryStream()
        Dim _stringBuilder As New System.Text.StringBuilder()
        Dim _stringWriter As New System.IO.StringWriter(_stringBuilder)
        Dim oXsltArgumentList As New XsltArgumentList()
        Dim I As Integer = 0
        For I = 1 To _RemoveLink
            Dim _Random As New Random(4)
            Dim _RandomNumber = _Random.Next Mod (5 - I)
            oXmlDocument.ChildNodes(1).ChildNodes(_RandomNumber).RemoveAll()
        Next
        oXslDocument.Transform(oXmlDocument, oXsltArgumentList, _stringWriter)
        litLinks.Text = _stringBuilder.ToString().Replace("~/", ResolveUrl("~/"))
    End Sub

    Dim _XMlFile As String
    Property XMLFile() As String
        Get
            Return _XMlFile
        End Get
        Set(ByVal value As String)
            _XMlFile = value
        End Set
    End Property

    Dim _RemoveLink As Integer = 1
    Property RemoveLink() As Integer
        Get
            Return _RemoveLink
        End Get
        Set(ByVal value As Integer)
            _RemoveLink = value
        End Set
    End Property
End Class
